﻿using System;
using System.Windows.Forms;
using System.Windows.Xps.Packaging;
using DataBaseLayer.Abstractions;
using DocumentManager.Abstractions.Factories;
using DocumentManager.Enums;
using DocumentManager.Forms;
using DocumentManager.WPFElements.UserControls;
using UserControl = System.Windows.Controls.UserControl;

namespace DocumentManager.Factories
{
	public class FormFactory : FormBaseFactory
	{
		#region Constructors

		public FormFactory(HelperBaseFactory helperFactory, ServiceBaseFactory serviceFactory)
			: base(helperFactory, serviceFactory) { }

		#endregion

		#region FormBaseFactory Members

		public override Form CreateForm(FormType formType)
		{
			switch (formType)
			{
				case FormType.Login:
					return new frmLogin(_helperFactory.CreatePasswordGenerator(), this);

				case FormType.DocumentManager:
					return new frmDocumentManager(this, _serviceFactory);

				case FormType.InfoCompanySettings:
					return new frmInfoCompanySettings(_helperFactory.CreateApplicationConfiguration());

				case FormType.LogOrders:
					return new frmLogOrder(
						_serviceFactory,
						_helperFactory.CreateApplicationConfiguration(),
						_helperFactory.CreateWordDocumentAdapter(),
						this);

				default:
					throw new NotImplementedException(string.Format("not implemented this form type"));
			}
		}

		public override Form CreateOrderForm(OrderType orderType)
		{
			switch (orderType)
			{
				case OrderType.Leave:
					return new frmLeaveOrder(
						_serviceFactory,
						_helperFactory.CreateApplicationConfiguration(),
						_helperFactory.CreateWordDocumentAdapter(),
						this);

				case OrderType.Dismissal:
					return new frmDismissalOrder(
						_serviceFactory,
						_helperFactory.CreateApplicationConfiguration(),
						_helperFactory.CreateWordDocumentAdapter(),
						this);

				case OrderType.BusinessTrip:
					return new frmBusinessTripOrder(
						_serviceFactory,
						_helperFactory.CreateApplicationConfiguration(),
						_helperFactory.CreateWordDocumentAdapter(),
						this);

				default:
					throw new NotImplementedException(string.Format("not implemented this order type"));
			}
		}

		public override UserControl CreateDocumentViewerUserControl(XpsDocument xpsDocumemt)
		{
			return new DocumentViewer(xpsDocumemt);
		}

		public override Form CreateDocumentViewerForm(string wordDocumentFilePath)
		{
			return new frmDocumentViewer(_helperFactory.CreateWordDocumentAdapter(), this, wordDocumentFilePath);
		}

		#endregion
	}
}
